/*
============================================================================
 Name        : PdBitmapGc.cpp
 Author      : Jian(raphyer@hotmail.com)
 Version     :
 Copyright   : GPL
 Description : CPdBitmapGc implementation
============================================================================
*/

#include "PdBitmapGc.h"
#include "PdDefine.h"

#include <aknutils.h> 


static CPdBitmapGc* __aphpaGc = NULL ;


CPdBitmapGc::~CPdBitmapGc()
{
    delete iBitmap ;
    delete iBitmapContext ;
    delete iBitmapDevice ;
}

void CPdBitmapGc::_initL(TDisplayMode aDispMode)
{
    TSize size ;
    AknLayoutUtils::LayoutMetricsSize(AknLayoutUtils::EScreen, size) ;

    iBitmap = new(ELeave) CFbsBitmap;
    iBitmap->Create(size, aDispMode);

    iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
    LogLeaveIfError(iBitmapDevice->CreateContext(iBitmapContext));
}

CPdBitmapGc* CPdBitmapGc::NewL(TDisplayMode aDispMode) 
{
    CPdBitmapGc* self = new(ELeave) CPdBitmapGc() ;
    CleanupStack::PushL(self) ;
    self->_initL(aDispMode) ;
    CleanupStack::Pop(self) ;
    return self ;
}

void CPdBitmapGc::Merge(CPdBitmapGc* aBgGc, CPdBitmapGc* aFrontGc, const TRect& aRect, TUint8 aTransparent) 
{
    if (!__aphpaGc)
        __aphpaGc = CPdBitmapGc::NewL(EGray256) ;

    __DD_ASSERT_DEFENSE(__aphpaGc, return) ;

    __aphpaGc->Gc()->SetBrushStyle(CGraphicsContext::ESolidBrush) ;
    __aphpaGc->Gc()->SetBrushColor(TRgb::Color256(aTransparent)) ;
    __aphpaGc->Gc()->Clear(aRect) ;

    aBgGc->Gc()->SetBrushColor(CGraphicsContext::ENullBrush) ;
    aBgGc->Gc()->AlphaBlendBitmaps(aRect.iTl, aFrontGc->Bitmap(), aRect,  __aphpaGc->Bitmap(), aRect.iTl) ;
}

/* End of File */
